<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../static/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户id</label>
        <div class="layui-input-block">
            <input type="text" id="stuId" name="stuId" lay-verify="required" lay-reqtext="用户id不能为空" placeholder="请输入用户id" value="" class="layui-input">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label required">姓名</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" id="stuName" name="stuName" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">-->
<!--            <tip>填写姓名。</tip>-->
<!--        </div>-->
<!--    </div>-->
    <div class="layui-form-item">
        <label class="layui-form-label required" >课程名</label>
        <div class="layui-input-block">
            <input type="text" id="couName" name="couName" lay-verify="required" lay-reqtext="课程名" placeholder="请输入课程名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required" >成绩</label>
        <div class="layui-input-block">
            <input type="text" id="score" name="score" lay-verify="required" lay-reqtext="成绩" placeholder="请输入成绩" value="" class="layui-input">
        </div>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">学分</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" id="credit" name="credit" placeholder="请输入学分" value="" class="layui-input">-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../../static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        function addscore(data) {
            //alert(JSON.stringify(data))
            $.ajax({
                type : "post",
                async:true,
                url : 'http://localhost:8888/teacher/addscore',
                data : JSON.stringify(data),
                dataType : "json",
                xhrFields: { //
                    withCredentials: true,
                },
                contentType : "application/json",
                success : function(resp){
                    console.log(resp.data)
                    //alert(resp)
                    if(resp.code === 1){
                        //失败 ， 显示登录失败的信息
                        layer.msg(resp.message);
                        alert("添加失败")
                    }else{
                        //alert(resp.data);
                        //成功  跳转页面 ， 显示登录成功的消息

                        alert("添加成功");

                        //sessionStorage.setItem("username" , resp.data)
                        window.history.back(-1);
                        layer.msg(resp.message);
                        //window.location = './index.html'
                    }
                }
            });
        }

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {

                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);
                console.log(data);

            });
            var scoreInfo = data.field;
            console.log(scoreInfo);
            addscore(scoreInfo);

        });

    });
</script>
</body>
</html>
